this.BX=this.BX||{};this.BX.Landing=this.BX.Landing||{};this.BX.Landing.UI=this.BX.Landing.UI||{};(function(e,s,t,i,a,n,r){"use strict";var l=function(e){babelHelpers.inherits(t,e);function t(e){var s;babelHelpers.classCallCheck(this,t);s=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(t).call(this,e));s.type=e.type;s.code=e.code;s.presets=e.presets;s.sync=e.sync;s.forms=e.forms;s.id="".concat(s.code.replace(".",""),"-").concat(BX.Landing.Utils.random());s.onSourceChangeHandler=e.onSourceChange;s.dynamicParams=e.dynamicParams;s.settingFieldsSelectors=["source","pagesCount","detailPage","useSef"];s.sourceField=s.createSourceField();s.pagesField=s.createPagesField();s.addField(s.sourceField);s.addField(s.pagesField);s.detailPageGroup=new BX.Landing.UI.Card.DynamicFieldsGroup({items:[s.createLinkField()]});s.addCard(s.detailPageGroup);return s}babelHelpers.createClass(t,[{key:"createSourceField",value:function e(){var i=this;var r=t.getSourceItems();var l=babelHelpers.slicedToArray(r,1),c=l[0];var o={source:c.value,filter:c.filter};if(s.Type.isPlainObject(this.dynamicParams)&&s.Type.isPlainObject(this.dynamicParams.settings)&&s.Type.isPlainObject(this.dynamicParams.settings.source)){o.source=this.dynamicParams.settings.source.source;o.filter=this.dynamicParams.settings.source.filter;o.sort=this.dynamicParams.settings.source.sort}return new a.SourceField({selector:"source",title:n.Loc.getMessage("LANDING_CARDS__SOURCE_FIELD_TITLE"),items:r,value:o,onValueChange:function e(a){var n=a.getValue();var r=t.getSources().find((function(e){return e.id===n.source}));setTimeout((function(){if(!i.sourceField.isDetailPageAllowed()){s.Dom.style(i.detailPageGroup.layout,"display","none")}else{s.Dom.style(i.detailPageGroup.layout,"display",null)}i.onSourceChangeHandler(r)}),0)}})}},{key:"createPagesField",value:function e(){return new BX.Landing.UI.Field.Pages({selector:"pagesCount",title:n.Loc.getMessage("LANDING_CARDS__PAGES_FIELD_TITLE"),value:this.dynamicParams.settings.pagesCount})}},{key:"createLinkField",value:function e(){var t={text:"",href:""};if(s.Type.isPlainObject(this.dynamicParams)&&s.Type.isPlainObject(this.dynamicParams.settings)&&s.Type.isPlainObject(this.dynamicParams.settings.detailPage)){t=this.dynamicParams.settings.detailPage}return new parent.BX.Landing.UI.Field.Link({selector:"detailPage",title:n.Loc.getMessage("LANDING_CARDS__DETAIL_PAGE_FIELD_TITLE"),textOnly:true,disableCustomURL:true,disableBlocks:true,disallowType:true,allowedTypes:[BX.Landing.UI.Field.LinkUrl.TYPE_HREF_PAGE],detailPageMode:true,sourceField:this.fields.find((function(e){return e.selector==="source"})),options:{siteId:i.Env.getInstance().getOptions().site_id,landingId:r.Main.getInstance().id,filter:{"=TYPE":i.Env.getInstance().getOptions().params.type}},content:t})}},{key:"serialize",value:function e(){var i=this;var a=this.sourceField.isDetailPageAllowed();return this.fields.reduce((function(e,n){if(n.selector==="detailPage"&&!a){return e}var r=n.getValue();if(i.settingFieldsSelectors.includes(n.selector)){if(n.selector==="source"){e.source=r.source}e.settings[n.selector]=r}else if(r==="@hide"||s.Type.isPlainObject(r)&&r.id==="@hide"){e.references[n.selector]="@hide";if(s.Dom.hasClass(n.layout,"landing-ui-field-dynamic-dropdown")){e.stubs[n.selector]=""}else if(s.Dom.hasClass(n.layout,"landing-ui-field-dynamic-image")){e.stubs[n.selector]={id:-1,src:"",alt:""}}}else if(t.isReference(r)||s.Type.isPlainObject(r)&&s.Type.isString(r.id)){if(t.isReference(r)){e.references[n.selector]={id:r}}else{e.references[n.selector]=r}}else{e.stubs[n.selector]=r}return e}),{settings:{},references:{},stubs:{}})}}],[{key:"getSources",value:function e(){return i.Env.getInstance().getOptions().sources}},{key:"getSourceItems",value:function e(){return t.getSources().map((function(e){return{name:e.name,value:e.id,url:e.url?e.url.filter:"",filter:e.filter,sort:{items:e.sort.map((function(e){return{name:e.name,value:e.id}}))},settings:e.settings}}))}},{key:"isReference",value:function e(i){var a=t.getSources();if(s.Type.isArray(a)){return a.some((function(e){if(s.Type.isArray(e.references)){return e.references.some((function(e){return e.id===i}))}return false}))}return false}}]);return t}(t.BaseForm);e.DynamicCardsForm=l})(this.BX.Landing.UI.Form=this.BX.Landing.UI.Form||{},BX,BX.Landing.UI.Form,BX.Landing,BX.Landing.UI.Field,BX.Landing,BX.Landing);
//# sourceMappingURL=dynamiccardsform.bundle.map.js